package com.warmlight.voicepacket.base;

import android.content.Context;
import android.widget.BaseAdapter;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by jason on 2018/5/21.
 */

public abstract class MBaseAdapter<T> extends BaseAdapter {
    public Context mContext;
    public List<T> mList;

    public MBaseAdapter(Context context, List<T> list) {
        super();
        this.mContext = context;
        this.mList = list;
    }

    @Override
    public int getCount() {
        return mList == null ? 0 : mList.size();
    }

    @Override
    public T getItem(int position) {
        return mList == null ? null : mList.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    public void setList(List<T> list){
        if(mList == null){
            mList = new ArrayList<>();
        }
        mList = list;
        notifyDataSetChanged();
    }

    public void addList(List<T> list){
        if(mList == null){
            mList = new ArrayList<>();
        }
        mList.addAll(list);
        notifyDataSetChanged();
    }

    public void clearList(){
        if(mList != null){
            mList.clear();
            notifyDataSetChanged();
        }
    }
}
